package com.xiaodu.validator.controller;

import com.xiaodu.validator.entity.Product;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.hibernate.validator.constraints.Length;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * @author: dutianjie
 * @date: 2021/3/31
 * @version: v1.0.0
 * @description: 描述
 **/
@RestController
@RequestMapping("validator")
@Api(tags = "商品操作")
@Validated
public class ProductController {

    public static final Logger log = LoggerFactory.getLogger(ProductController.class);

    @ApiOperation(value = "获取商品详情", httpMethod = "GET")
    @GetMapping("product")
    public Product getProduct(@Length(max = 32, min = 32, message = "id长度必须为32位") @RequestParam String id) throws Exception {
        Product product = new Product();
        product.setId(id);
        product.setName("xiaomi 11");
        product.setPrice(199900L);
        return product;
    }

    @ApiOperation(value = "添加商品信息", httpMethod = "POST")
    @PostMapping("product")
    public String addProduct(@Validated Product product) throws Exception {
        return product.getId();
    }


}
